Understand that all indexing operations are asynchronous and learn how to wait for a task to finish.
taskId
which you can use with the waitTask
method. Using this method guarantees that a job has finished before proceeding with a new request. There are a few situations when this comes in handy:
waitTask
to manage dependencies, for example, when deleting an index before creating a new index with the same name or clearing an index before adding new objects.replaceAllObjects
method which does it all for you.waitTask
in debugging scenarios, when you’re testing a search immediately after updating an index.waitTask
makes your indexing operations synchronous, thus slows them down.
Conversely, you don’t need to use waitTask
in place of the asynchronous mechanisms of your programming language. You can ensure that tasks are queued in order by using promises or callbacks.